import {createRouter,createWebHashHistory} from "vue-router"
import HelloWorld from '../components/HelloWorld.vue'
import DataTable from '../components/DataTable.vue'
import AdminTable from '../components/AdminTable.vue'
import TeacherTable from '../components/TeacherTable.vue'
import ClazzTable from '../components/ClazzTable.vue'
import GradeTable from '../components/GradeTable'
import HomePage from '../components/HomePage.vue'
import PersonalCenter from '../components/PersonalCenter.vue'
import LoginFrom from '../components/LoginFrom.vue'
import AdminNavigation from '../components/AdminNavigation.vue'
import TeahcerAdmin from '../components/TeahcerAdmin.vue'
import Course from '../components/Course.vue'
import Article from '../components/Article.vue'
import TeacherPersonalCenter from '../components/TeacherPersonalCenter.vue'
import UpdateArticle from '../components/UpdateArticle.vue'
import UpdataeCourse from '../components/UpdataeCourse.vue'
import store from '../store'
const router= createRouter({
    history : createWebHashHistory(),
    routes:[
        {
            path:'/',
            component:LoginFrom
        },
        {
            name:'LoginFrom',
            path:'/LoginFrom',
            component:LoginFrom,
        },
        {
            name:'TeahcerAdmin',
            path:'/TeahcerAdmin',
            component:TeahcerAdmin,
            children:[
                {
                    name:'Course',
                    path:'Course',
                    component:Course
                },
                {
                    name:'Article',
                    path:'Article',
                    component:Article
                },
                {
                    name:'TeacherPersonalCenter',
                    path:'TeacherPersonalCenter',
                    component:TeacherPersonalCenter
                },
                {
                    name:'UpdateArticle',
                    path:'UpdateArticle',
                    component:UpdateArticle
                },
                {
                    name:'UpdataeCourse',
                    path:'UpdataeCourse',
                    component:UpdataeCourse
                }
            ]
        },
        {
            name:'AdminNavigation',
            path:'/AdminNavigation',
            component:AdminNavigation,
            children:[
                        {
                            name:'HelloWorld',
                            path:'HelloWorld',
                            component:HelloWorld
                        },
                        {
                            name:'DataTable',
                            path:'DataTable',
                            component:DataTable
                        },
                        {
                            name:'AdminTable',
                            path:'AdminTable',
                            component:AdminTable
                        },
                        {
                            name:'TeacherTable',
                            path:'TeacherTable',
                            component:TeacherTable
                        },
                        {
                            name:'ClazzTable',
                            path:'ClazzTable',
                            component:ClazzTable
                        },
                        {
                            name:'GradeTable',
                            path:'GradeTable',
                            component:GradeTable
                        },
                        {
                            name:'HomePage',
                            path:'HomePage',
                            component:HomePage
                        },
                        {
                            name:'PersonalCenter',
                            path:'PersonalCenter',
                            component:PersonalCenter
                        }
            ]
        }
    ]
})
router.beforeEach((to,from,next)=>{
    if(to.path==='/AdminNavigation' 
    || to.path==='/AdminNavigation/DataTable' 
    || to.path==='/AdminNavigation/TeacherTable' 
    || to.path==='/AdminNavigation/AdminTable' 
    || to.path==='/AdminNavigation/ClazzTable' 
    || to.path==='/AdminNavigation/GradeTable' 
    || to.path==='/AdminNavigation/HomePage' 
    || to.path==='/AdminNavigation/PersonalCenter'
    || to.path==='/TeahcerAdmin/Course'
    || to.path==='/TeahcerAdmin/Article'
    || to.path==='/TeahcerAdmin/TeacherPersonalCenter'
    || to.path==='/TeahcerAdmin/UpdateArticle'
    || to.path==='/TeahcerAdmin/UpdataeCourse'
    ){
        if(store.state.LoginState==true){
            next()
        }else{
            alert("请先登录！！")
            router.push('/LoginFrom')
        }
    }else{
        next()
    }
})
export default router